package com.itheima.health.controller.mobile;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.result.Result;
import com.itheima.health.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController("MobileSetmealController")
@RequestMapping("/mobile/setmeal")
@Api(tags = "用户端-套餐相关接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    /**
     * 根据id查询套餐信息
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(int id){
        log.info("根据id查询套餐信息:{}", id);
        Setmeal setmeal = null;
        try{
            setmeal = setmealService.findById(id);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConst.QUERY_SETMEAL_FAIL);
        }
        return new Result(true,MessageConst.QUERY_SETMEAL_SUCCESS,setmeal);
    }

    /**
     * 获取所有套餐信息
     * @return
     */
    @GetMapping("/getSetmeal")
    @ApiOperation("获取所有套餐信息")
    public Result getSetmeal(){
        log.info("获取所有套餐信息");
        List<Setmeal> list = null;
        try{
            list = setmealService.findAll();
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConst.GET_SETMEAL_LIST_FAIL);
        }
        return new Result(true, MessageConst.GET_SETMEAL_LIST_SUCCESS,list);
    }
}
